package com.note.feng.juc.forkJoin;

import java.util.concurrent.*;

/**
 * 测试 forkJoin
 * @author yuhf
 */
public class ForkJoinTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException, TimeoutException {

        long start = System.currentTimeMillis();
        ForkJoinPool forkJoinPool = new ForkJoinPool();
        //创建一个累加任务，计算由1加到10
        AccumulateTask countTask = new AccumulateTask(1, 100);
        Future<Integer> future = forkJoinPool.submit(countTask);
        Integer sum = future.get(1, TimeUnit.SECONDS);
        System.out.println(System.currentTimeMillis() - start);
        System.out.println("最终的计算结果：" + sum);
        //预期的结果为5050
        System.out.println(sum == 5050);
    }
}
